package com.siwei.mes.entity.experiment.coarseAggregate;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 粗骨料-堆积密度
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/02/25 21:29
 */
@Data
@Accessors(chain = true)
public class CoarseAggregateDjmd {
    @ApiModelProperty(value = "取样质量")
    private String qyzl = "";
    @ApiModelProperty(value = "容量筒质量")
    private String rltzl = "";
    @ApiModelProperty(value = "容量筒体积")
    private String rlttj = "";
    @ApiModelProperty(value = "平均值")//1
    private String pjz = "";
    @ApiModelProperty(value = "单项结论")//1
    private String dxjl = "";
    @ApiModelProperty(value = "检测日期")
    private String jcrq = "";
    @ApiModelProperty(value = "空隙率")
    private String kxl = "";
    @ApiModelProperty(value = "堆积密度信息")
    private List<CoarseAggregateDjmd.DjmdInfo> djmdInfo = Collections.singletonList(new CoarseAggregateDjmd.DjmdInfo());

    @Data
    @Accessors(chain = true)
    @ApiModel("堆积密度信息")
    public static class DjmdInfo {
        @ApiModelProperty(value = "试样质量")
        private String syzl = "";
        @ApiModelProperty(value = "总质量")
        private String zzl = "";
        @ApiModelProperty(value = "结果")
        private String jg = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        CoarseAggregateDjmd entity = new CoarseAggregateDjmd();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, CoarseAggregateDjmd.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, CoarseAggregateDjmd.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        CoarseAggregateDjmd entity = JsonUtils.getObject(objJson, CoarseAggregateDjmd.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getPjz()) || "null".equals(entity.getPjz())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        /*if (StringUtils.isBlank(entity.getDxjl()) || "null".equals(entity.getDxjl())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }*/
        return null;
    }

    public static void setValue(CoarseAggregateDjmd entity, Map<String, Object> data) {
        List<CoarseAggregateDjmd.DjmdInfo> djmdbInfoList = new ArrayList<>();
        DjmdInfo djmdbInfo1 = new DjmdInfo();
        if(data.get("S1") != null){
            entity.setRltzl(data.get("S1").toString());
        }
        if(data.get("S2") != null){
            djmdbInfo1.setZzl(data.get("S2").toString());
        }
        if(data.get("S3") != null){
            entity.setRlttj(data.get("S2").toString());
        }
        if(data.get("S4") != null){
            djmdbInfo1.setJg(data.get("S4").toString());
        }
        djmdbInfoList.add(djmdbInfo1);
        DjmdInfo djmdbInfo2 = new DjmdInfo();
        if(data.get("S5") != null){
            entity.setRltzl(data.get("S5").toString());
        }
        if(data.get("S6") != null){
            djmdbInfo2.setZzl(data.get("S6").toString());
        }
        if(data.get("S7") != null){
            entity.setRlttj(data.get("S7").toString());
        }
        if(data.get("S8") != null){
            djmdbInfo2.setJg(data.get("S8").toString());
        }
        djmdbInfoList.add(djmdbInfo2);
        entity.setDjmdInfo(djmdbInfoList);
        if(data.get("S9") != null){
            entity.setPjz(data.get("S9").toString());
        }
        if(data.get("S11") != null){
            entity.setKxl(data.get("S11").toString());
        }
    }
}
